package com.ruoyi.mobile.model.bo.huawei;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;

import java.time.LocalDateTime;
import java.util.Date;

public class AccessTokenBo {

    /** access_token */
    private String accessToken;

    /** access_token的过期时间 */
    private String accessTokenExpire;

    /** refresh_token */
    private String refreshToken;

    /** 用户授予的权限 */
    private String scope;

    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    public String getAccessTokenExpire() {
        return accessTokenExpire;
    }

    public void setAccessTokenExpire(String accessTokenExpire) {
        this.accessTokenExpire = accessTokenExpire;
    }

    public String getRefreshToken() {
        return refreshToken;
    }

    public void setRefreshToken(String refreshToken) {
        this.refreshToken = refreshToken;
    }

    public String getScope() {
        return scope;
    }

    public void setScope(String scope) {
        this.scope = scope;
    }

    public AccessTokenBo buildByHuaweiAccessTokenBo(HuaweiAccessTokenBo huaweiAccessTokenBo) {
        this.accessToken = huaweiAccessTokenBo.getAccess_token();
        this.refreshToken = huaweiAccessTokenBo.getRefresh_token();
        this.scope = huaweiAccessTokenBo.getScope();
        int expireSecond = huaweiAccessTokenBo.getExpires_in() - 300; //token有效期减去5分钟
        this.accessTokenExpire = LocalDateTimeUtil.format(LocalDateTime.now().plusSeconds(expireSecond),"yyyy-MM-dd HH:mm:ss");
        return this;
    }


    public AccessTokenBo buildByRefreshHuaweiAccessTokenBo(RefreshHuaweiAccessTokenBo refreshHuaweiAccessTokenBo) {
        this.accessToken = refreshHuaweiAccessTokenBo.getAccess_token();
        this.refreshToken = refreshHuaweiAccessTokenBo.getRefresh_token();
        this.scope = refreshHuaweiAccessTokenBo.getScope();
        int expireSecond = refreshHuaweiAccessTokenBo.getExpires_in() - 300; //token有效期减去5分钟
        this.accessTokenExpire = LocalDateTimeUtil.format(LocalDateTime.now().plusSeconds(expireSecond),"yyyy-MM-dd HH:mm:ss");
        return this;
    }

}
